import { translateByCode } from '@/lib/getTransData.js';
import validator from '../index.js';
import {
  OrganizationUnitCreateInput,
  IdentityUserCreateDto,
  IdentityRoleCreateInput
} from '@/lib/form/swaggerForm.js';
// 新增/修改 - 下属部门
export class FormAddUnitVO_Rules extends OrganizationUnitCreateInput {
  constructor() {
    super();
    this.displayName = [
      { required: true, message: '单位/部门名称不能为空', trigger: 'blur' }
    ];
    this.typeCode = [validator.required('机构类型不能为空', 'change')];
    this.provinceCode = [validator.required('地理范围不能为空', 'change')];
  }
}
// 新增/编辑 - 新员工
export class FormAddUserVo_Rules extends IdentityUserCreateDto {
  constructor() {
    super();
    this.name = [{ required: true, message: '姓名不能为空', trigger: 'blur' }];
    this.phoneNumber = [
      validator.required('手机号码不能为空'),
      {
        validator(rule, value, callback) {
          callback(validator.checkPhone(value, translateByCode('rules.validTelephone')));
        },
        trigger: 'blur'
      }
    ];
    this.isEnabled = [
      { required: true, message: '请选择状态', trigger: 'blur' }
    ];
    this.password = [
      validator.required(translateByCode('rules.requiredPassword')),
      {
        validator(rule, value, callback) {
          callback(validator.checkPwd(value, translateByCode('rules.validPassword')));
        },
        trigger: 'change'
      }
    ];
    this.roleIds = [
      { required: true, message: '请选择角色权限', trigger: 'change' }
    ];
  }
}
// 新增/编辑 - 角色
export class FormAddRoleVO_Rules extends IdentityRoleCreateInput {
  constructor() {
    super();
    this.displayName = [
      { required: true, message: '角色名称不能为空', trigger: 'blur' }
    ];
    this.permissions = [
      { type: 'array', required: true, message: '请至少选择一个功能', trigger: 'change' }
    ];
    this.organizationUnitIds = [
      { type: 'array', required: true, message: '请至少选择一个数据范围', trigger: 'change' }
    ];
  }
}
// 转移机构
export class OrganizationUnitMoveInput_Rules {
  constructor() {
    this.newParentId = [validator.required('请选择一个机构', 'change')];
  }
}
// 分配道馆系统
export class UpdateOrganizationUnitEditionInput_Rules {
  constructor() {
    this.editionId = [
      { required: true, message: '请选择道馆版本', trigger: 'change' }
    ];
    this.phoneNumber = [
      validator.required('手机号码不能为空'),
      {
        validator(rule, value, callback) {
          callback(validator.checkPhone(value, translateByCode('rules.validTelephone')));
        },
        trigger: 'blur'
      }
    ];
  }
}
